package com.bq;

public class StringUtils {
    //判断字符串是否为空
    public static boolean isNull(String str){
        if(str==null || str.equals("")){
            return true;
        }else{
            return false;
        }
    }
    //判断字符串不是null
    public static boolean isNotNull(String str){
        if(str!=null && !str.equals("")){
            return true;
        }else{
            return false;
        }
    }
    //判断过滤空格后的字符串是否有值
    public static boolean isTrimNotNull(String str){
        if(str!=null && !str.equals("") && !str.trim().equals("")){
            return true;
        }else{
            return false;
        }
    }
    //判断是否尾合格邮箱
    public boolean isEmail(String str){
        if(isNotNull(str)){
            String reg_email="^[a-z0-9A-Z]+[- |a-z0-9A-Z .]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$";
            return str.matches(reg_email);
        }else{
            return false;
        }
    }
//判断是否尾手机号码
    public static boolean isPhone(String phone){
        if(isNotNull(phone)){
            String reg_phone="(13[0-9]|14[0145678]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}";
            return phone.matches(reg_phone);
        }else{
            return false;
        }
    }
//判断是否全部尾字母
    public static boolean isLetter(String letter){
        if(isNotNull(letter)){
            String reg_letter="[a-zA-Z]+";
            return letter.matches(reg_letter);
        }else{
            return false;
        }
    }
//反转字符串
    public static String turnfz(String letter){
        String res="";
        char[] chars=letter.toCharArray();
        for(char c:chars){
            res=c+res;
        }
        return res;
    }
//隐藏字符串
    public static String ycstr(String str,int start,int end){
        if(isNotNull(str)){
            String res="";
            char[] chars=str.toCharArray();
            for (int i=0;i<chars.length;i++){
                if(i>=start && i<=end){
                    res=res+"*";
                }else{
                    res=res+chars[i];
                }
            }
            return res;
        }else{
            return "";
        }
    }

//在方法中进行测试
    public static void main(String[] args) {
        System.out.println(isNotNull(""));
        System.out.println(isNull("11111"));
        System.out.println(isPhone("15624833"));
        System.out.println(isLetter("asdasd"));
        System.out.println(ycstr("123adc",2,3));
    }
}
